package com.ruisoft.business.salary.service;

import com.ruisoft.base.bean.QueryData;
import com.ruisoft.base.dao.BaseDao;
import com.ruisoft.base.service.BaseService;
import com.ruisoft.common.CommonUtil;
import com.ruisoft.core.param.CacheDataFactory;
import com.ruisoft.core.param.RequestUtil;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SalaryService extends BaseService {

    @Autowired
    public BaseDao baseDao;

    @Autowired
    private CacheDataFactory cacheData;
    
    
    public List<JSONObject> searchForPage(QueryData q) throws Exception {
        List<JSONObject> itemData = search(q, "salary.select.salaryinfo.query");
        return itemData;
    }

    public JSONObject saveSalary(JSONObject jsonData) throws Exception {
        jsonData.put("salaryId", CommonUtil.getUUID());
        jsonData.put("sal_state", "1");
        jsonData.put("create_uid", RequestUtil.getCurrentUserAccount());
        jsonData.put("create_date", CommonUtil.getCurDateTime());
        baseDao.add(jsonData, "salary.add.salaryinfo.add");

        return jsonData;
    }

	public int deleteSalary(String id) throws Exception {
		int status = 0;
        status = baseDao.deleteCode(id,"salary.delete.salaryinfo.delete");
        return status;
	}

	public JSONObject searchSalary(String salaryid) throws Exception {
		List<JSONObject> salaryDataList = baseDao.queryId(salaryid, "salary.select.salaryinfo.salaryid");
    	JSONObject salarydata = new JSONObject();
    	if(salaryDataList.size()>0)
    		salarydata = salaryDataList.get(0);
    	return salarydata;
	}

	public JSONObject updateSalary(JSONObject jsonData) throws Exception {
		baseDao.update(jsonData, "salary.update.salaryinfo.update");
        return jsonData;
	}
}
